<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="icon" href="../../logo.svg" />
    <title>天气案例_监视属性_深度监视</title>
  </head>
  <body>
    <div id="root">
      <h2>今天天气很{{info}}</h2>
      <button @click="isHot = !isHot">切换天气</button>

      <hr />
      <h3>a的值是: {{numbers.a}}</h3>
      <button @click="numbers.a++">点我让a+1</button>

      <hr />
      <h3>b的值是: {{numbers.b}}</h3>
      <button @click="numbers.b++">点我让b+1</button>
    </div>

    <script src="../../vue.js"></script>
    <script>
      Vue.config.productionTip = false; // 阻止 vue 在启动时生成生产提示。

      const vm = new Vue({
        el: "#root",
        data: {
          isHot: true,
          numbers: {
            a: 1,
            b: 1,
          },
        },
        methods: {},
        computed: {
          info() {
            return this.isHot ? "炎热" : "凉爽";
          },
        },
        watch: {
          isHot: {
            handler(currentValue, prevValue) {
              console.log(currentValue, prevValue);
            },
          },
          // "numbers.a": {
          //   handler(currentValue, prevValue) {
          //     console.log("a被改变了", currentValue, prevValue);
          //   },
          // },
          numbers: {
            deep: true, // 深度监视
            handler(currentValue, prevValue) {
              console.log("numbers被改变", currentValue, prevValue);
            },
          },
        },
      });
    </script>
  </body>
</html>
